/**
 * Created by Administrator on 2017/12/9.
 */
export default {
    dateFormat :function(date,fmt){
        if(!date){
            return "";
        }
        date = new Date(date);
        if(/(y+)/.test(fmt)){
            fmt = fmt.replace(RegExp.$1, (date.getFullYear()+'').substr(4-RegExp.$1.length));
        }
        let o = {
            'M+': date.getMonth()+1,
            'd+': date.getDate(),
            'h+': date.getHours(),
            'm+': date.getMinutes(),
            's+': date.getSeconds()
        }
        for(let k in o){
            let str = o[k]+'';
            if(new RegExp(`(${k})`).test(fmt)){
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length===1)?str:padLeftZero(str));
            }
        }
        return fmt;
    },
        //格式化日期

         setDate(date){
        y=date.getFullYear();
        m=date.getMonth()+1;
        d=date.getDate();
        m=m<10?"0"+m:m;
        d=d<10?"0"+d:d;
        return y+"-"+m+"-"+d;
    },


    /**
     * 获取当前月的第一天
     */
     getCurrentMonthFirst(){
        var date=new Date();
        date.setDate(1);
        return date;
    },
    /**
     * 获取当前月的最后一天
     */
    getCurrentMonthLast(){
        var date=new Date();
        var currentMonth=date.getMonth();
        var nextMonth=++currentMonth;
        var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
        var oneDay=1000*60*60*24;
        return new Date(nextMonthFirstDay-oneDay);
    },
    //计算签约率
    calculateSignRate:function(total,sign){
        if(total == 0){
            return '0%'
        }
        return (Math.round(sign / total * 10000) / 100.00 + "%");
    }

};
function padLeftZero(str){
    return ('00'+str).substr(str.length);
}